package com.kancy.demo.streamplus.runner;

import com.kancy.demo.streamplus.channel.DevChannel;
import com.kancy.demo.streamplus.channel.DynamicChannelResolver;
import com.kancy.demo.streamplus.channel.TestChanel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * <p>
 * SendMessageRunner
 * <p>
 *
 * @author: kancy
 * @date: 2020/3/13 10:22
 **/
@Slf4j
@RequiredArgsConstructor
@Component
public class SendMessageRunner implements ApplicationRunner {

    private final DevChannel devChannel;
    private final TestChanel testChanel;

    private final DynamicChannelResolver dynamicChannelResolver;

    @Override
    public void run(ApplicationArguments args) {
        devChannel.output().send(MessageBuilder.withPayload("兄弟，我来自开发环境！").build());
        testChanel.output().send(MessageBuilder.withPayload("兄弟，我来自测试环境！").build());

//        dynamicChannelResolver.getChannel("dynamic.dev")
//                .send(MessageBuilder.withPayload("兄弟，我来自开发环境！").build());
//        dynamicChannelResolver.getChannel("dynamic.test")
//                .send(MessageBuilder.withPayload("兄弟，我来自测试环境！").build());
    }

}
